namespace Matrix.Configuration.Services
{
    /// <summary>
    /// 配置事件处理选项
    /// </summary>
    public class ConfigurationEventOptions
    {
        /// <summary>
        /// 是否启用事件持久化
        /// </summary>
        public bool EnableEventPersistence { get; set; } = true;

        /// <summary>
        /// 是否启用事件追踪
        /// </summary>
        public bool EnableEventTracing { get; set; } = true;

        /// <summary>
        /// 是否启用事件指标
        /// </summary>
        public bool EnableEventMetrics { get; set; } = true;

        /// <summary>
        /// 事件最大保留天数
        /// </summary>
        public int MaxEventRetentionDays { get; set; } = 30;

        /// <summary>
        /// 批量处理配置
        /// </summary>
        public BatchProcessingOptions BatchProcessing { get; set; } = new();

        /// <summary>
        /// 重试策略配置
        /// </summary>
        public RetryPolicyOptions RetryPolicy { get; set; } = new();

        /// <summary>
        /// 分发策略配置
        /// </summary>
        public DistributionStrategyOptions DistributionStrategy { get; set; } = new();

        /// <summary>
        /// 死信队列处理配置
        /// </summary>
        public DeadLetterHandlingOptions DeadLetterHandling { get; set; } = new();
    }

    /// <summary>
    /// 批量处理选项
    /// </summary>
    public class BatchProcessingOptions
    {
        /// <summary>
        /// 是否启用批量处理
        /// </summary>
        public bool Enabled { get; set; } = true;

        /// <summary>
        /// 批量大小
        /// </summary>
        public int BatchSize { get; set; } = 100;

        /// <summary>
        /// 刷新间隔
        /// </summary>
        public System.TimeSpan FlushInterval { get; set; } = System.TimeSpan.FromSeconds(30);

        /// <summary>
        /// 最大等待时间
        /// </summary>
        public System.TimeSpan MaxWaitTime { get; set; } = System.TimeSpan.FromMinutes(5);

        /// <summary>
        /// 最大批量事件数量
        /// </summary>
        public int MaxBatchEvents { get; set; } = 1000;
    }

    /// <summary>
    /// 重试策略选项
    /// </summary>
    public class RetryPolicyOptions
    {
        /// <summary>
        /// 最大重试次数
        /// </summary>
        public int MaxRetryAttempts { get; set; } = 3;

        /// <summary>
        /// 初始延迟时间
        /// </summary>
        public System.TimeSpan InitialDelay { get; set; } = System.TimeSpan.FromSeconds(1);

        /// <summary>
        /// 最大延迟时间
        /// </summary>
        public System.TimeSpan MaxDelay { get; set; } = System.TimeSpan.FromMinutes(5);

        /// <summary>
        /// 退避倍数
        /// </summary>
        public double BackoffMultiplier { get; set; } = 2.0;

        /// <summary>
        /// 是否启用指数退避
        /// </summary>
        public bool UseExponentialBackoff { get; set; } = true;
    }

    /// <summary>
    /// 分发策略选项
    /// </summary>
    public class DistributionStrategyOptions
    {
        /// <summary>
        /// 本地事件阈值（0-1之间，超过此值使用分布式事件）
        /// </summary>
        public double LocalEventThreshold { get; set; } = 0.7;

        /// <summary>
        /// 分布式事件阈值（0-1之间，超过此值强制使用分布式事件）
        /// </summary>
        public double DistributedEventThreshold { get; set; } = 0.9;

        /// <summary>
        /// 关键配置分类列表
        /// </summary>
        public System.Collections.Generic.List<string> CriticalConfigCategories { get; set; } = new()
        {
            "Database", "Security", "Auth", "Connection"
        };

        /// <summary>
        /// 缓存配置分类列表
        /// </summary>
        public System.Collections.Generic.List<string> CacheConfigCategories { get; set; } = new()
        {
            "Cache", "Redis", "Memory"
        };

        /// <summary>
        /// 本地服务配置键模式列表
        /// </summary>
        public System.Collections.Generic.List<string> LocalServiceKeyPatterns { get; set; } = new()
        {
            "*.Internal.*", "*.Local.*", "Service.*"
        };

        /// <summary>
        /// 是否启用本地事件缓存
        /// </summary>
        public bool EnableLocalEventCache { get; set; } = true;

        /// <summary>
        /// 本地事件缓存过期时间
        /// </summary>
        public System.TimeSpan LocalEventCacheTtl { get; set; } = System.TimeSpan.FromMinutes(5);
    }

    /// <summary>
    /// 死信队列处理选项
    /// </summary>
    public class DeadLetterHandlingOptions
    {
        /// <summary>
        /// 是否启用死信队列处理
        /// </summary>
        public bool Enabled { get; set; } = true;

        /// <summary>
        /// 最大重试次数
        /// </summary>
        public int MaxRetryCount { get; set; } = 5;

        /// <summary>
        /// 自动重试间隔
        /// </summary>
        public System.TimeSpan AutoRetryInterval { get; set; } = System.TimeSpan.FromHours(1);

        /// <summary>
        /// 是否需要人工审批
        /// </summary>
        public bool ManualApprovalRequired { get; set; }

        /// <summary>
        /// 死信队列保留天数
        /// </summary>
        public int DeadLetterRetentionDays { get; set; } = 7;

        /// <summary>
        /// 死信队列最大大小
        /// </summary>
        public int MaxDeadLetterQueueSize { get; set; } = 10000;
    }
}